/**
 * 
 */
package com.cjlu.qiuyujia.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
  
/**
 * @author Administrator
 * 
 */
public class JDBCConnection {
	// 数据库驱动
	private String driveClass;

	// 连接数据库中的数据表的地址
	private String url;

	private String username;
	private String password;

	/*
	 * 数据库驱动
	 * "com.mysql.jdbc.Driver"
	 * "oracle.jdbc.driver.OracleDriver"
	 * "com.microsoft.jdbc.sqlserver.SQLServerDriver"
	 * 
	 * 数据库数据表的url
	 * "jdbc:mysql://localhost:3306/daogou?useUnicode=true&characterEncoding=utf8"
	 * "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=demo";
	 * "jdbc:oracle:thin:@localhost:1521:dbhouse"
	 *
	 */
	// 连接mysql
	{
		driveClass = "com.mysql.jdbc.Driver";
		url = "jdbc:mysql://localhost:3306/daogou?useUnicode=true&characterEncoding=utf8";
		username = "root";
		password = "123";
	}

	public Connection getConection() throws SQLException,
			ClassNotFoundException {
		try {
			// 注册驱动
			Class.forName(driveClass);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			throw e;
		}
		return DriverManager.getConnection(url, username, password);
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		JDBCConnection conn = new JDBCConnection();
		try {
			conn.getConection();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}
